import request from './request'

export function login (data: {
    code: string
    appId: string
}): Promise<{
    auditStatus: number
    openid: string
    role: number
    salesId: number
    sessionKey?: string
    token: string
}> {
    return request.post('/api/v1/wx-crm/getAppletUserInfo', data)
}
// 解密手机号
export function encryptedPhoneData (data: {
    appId: string,
    encryptedData: string,
    iv: string,
    openid: string
}) {
    return request.post('/api/v1/wx-crm/decryptedPhoneData', data)
}
// 新建用户
/**
 * 注册
 */
export function register (data: {
    openId: string
    salesName: string
    realName: string
    salesHeadUrl: string
    phone?: string
    sex: number
    idCardNo: string
}) {
    return request.post('/api/v1/crm/sales/sales-info', data)
}

// 上传url地址
export function uploadUrl (data: {
    file: string
}) {
    return request.post('/api/v1/crm/file-detail/upload', data)
}

// 获取用户基本信息
export interface GetUserInfoResDto {
    id: number
    is_super: boolean
    source: string
    mobile: string
    avatar: string
    name: string
    phone: string
    salesName: string
    salesHeadUrl: string
}
//  /api/v1/wx-crm/getAppletUserInfo
export function getUserInfo (): Promise<GetUserInfoResDto> {
    return request.get('/api/v1/crm/sales/sales-info')
}

// 公司名称自动完成
export function companyNameAuto (params: { search: string }): Promise<string[]> {
    return request.get('/company/autoComplete', params)
}

/**
 * 退出登录（解绑）
 */
export function unbind (): Promise<void> {
    return request.post('/passport/unbind')
}

/**
 * 意见与反馈
 */
export function addOpinion (data: {
    type: string
    content: string
    fileIds: string
}): Promise<void> {
    return request.post('/feedback/add', data)
}
